From: Marina Zhurakhinskaya Date: Tue, 9 Dec 2008 22:10:43 +0000 (+0000) Subject: Convert some variable and file names to lowerCamelCase. X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~1013^2^2~11518 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=98860733bbb94b9b9fc6df550bb98c6d37e6a95e;p=gnome-shell.git Convert some variable and file names to lowerCamelCase. Remove unused variables in AppDisplay::_filterAdd(). svn path=/trunk/; revision=123 --- diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js new file mode 100644 index 000000000..a9ff0200c --- /dev/null +++ b/js/ui/appDisplay.js @@ -0,0 +1,349 @@ +/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */ + +const Signals = imports.signals; +const Clutter = imports.gi.Clutter; +const Gio = imports.gi.Gio; +const Pango = imports.gi.Pango; +const Gtk = imports.gi.Gtk; + +const Tidy = imports.gi.Tidy; +const Big = imports.gi.Big; +const Meta = imports.gi.Meta; +const Shell = imports.gi.Shell; + +// TODO - move this into GConf once we're not a plugin anymore +// but have taken over metacity +// This list is taken from GNOME Online popular applications +// http://online.gnome.org/applications +// but with nautilus removed +const DEFAULT_APPLICATIONS = [ + 'mozilla-firefox.desktop', + 'gnome-terminal.desktop', + 'evolution.desktop', + 'evince.desktop', + 'gedit.desktop', + 'mozilla-thunderbird.desktop', + 'totem.desktop', + 'gnome-file-roller.desktop', + 'rhythmbox.desktop', + 'epiphany.desktop', + 'xchat.desktop', + 'openoffice.org-1.9-writer.desktop', + 'emacs.desktop', + 'gnome-system-monitor.desktop', + 'openoffice.org-1.9-calc.desktop', + 'eclipse.desktop', + 'openoffice.org-1.9-impress.desktop', + 'vncviewer.desktop' +]; + +const APPDISPLAY_NAME_COLOR = new Clutter.Color(); +APPDISPLAY_NAME_COLOR.from_pixel(0xffffffff); +const APPDISPLAY_COMMENT_COLOR = new Clutter.Color(); +APPDISPLAY_COMMENT_COLOR.from_pixel(0xffffffbb); +const APPDISPLAY_BACKGROUND_COLOR = new Clutter.Color(); +APPDISPLAY_BACKGROUND_COLOR.from_pixel(0x000000ff); +const APPDISPLAY_SELECTED_BACKGROUND_COLOR = new Clutter.Color(); +APPDISPLAY_SELECTED_BACKGROUND_COLOR.from_pixel(0x00ff0055); + +const APPDISPLAY_HEIGHT = 50; +const APPDISPLAY_PADDING = 4; + +function AppDisplayItem(node, width) { + this._init(node, width); +} + +AppDisplayItem.prototype = { + _init: function(appInfo, width) { + let me = this; + this._appInfo = appInfo; + + let name = appInfo.get_name(); + + let iconTheme = Gtk.IconTheme.get_default(); + + this._group = new Clutter.Group({reactive: true, + width: width, + height: APPDISPLAY_HEIGHT}); + this._group.connect('button-press-event', function(group, e) { + me.emit('activate'); + return true; + }); + this._bg = new Big.Box({ background_color: APPDISPLAY_BACKGROUND_COLOR, + corner_radius: 4, + x: 0, y: 0, + width: width, height: APPDISPLAY_HEIGHT }); + this._group.add_actor(this._bg); + + this._icon = new Clutter.Texture({ width: 48, height: 48, x: 0, y: 0 }); + let gicon = appInfo.get_icon(); + let path = null; + if (gicon != null) { + let iconinfo = iconTheme.lookup_by_gicon(gicon, 48, Gtk.IconLookupFlags.NO_SVG); + if (iconinfo) + path = iconinfo.get_filename(); + } + + if (path) + this._icon.set_from_file(path); + this._group.add_actor(this._icon); + + let comment = appInfo.get_description(); + let text_width = width - (me._icon.width + 4); + this._name = new Clutter.Label({ color: APPDISPLAY_NAME_COLOR, + font_name: "Sans 14px", + width: text_width, + ellipsize: Pango.EllipsizeMode.END, + text: name, + x: this._icon.width + 4, + y: 0}); + this._group.add_actor(this._name); + this._comment = new Clutter.Label({ color: APPDISPLAY_COMMENT_COLOR, + font_name: "Sans 12px", + width: text_width, + ellipsize: Pango.EllipsizeMode.END, + text: comment, + x: this._name.x, + y: this._name.height + 4}) + this._group.add_actor(this._comment); + this.actor = this._group; + }, + launch: function() { + this._appInfo.launch([], null); + }, + appInfo: function () { + return this._appInfo; + }, + markSelected: function(isSelected) { + let color; + if (isSelected) + color = APPDISPLAY_SELECTED_BACKGROUND_COLOR; + else + color = APPDISPLAY_BACKGROUND_COLOR; + this._bg.background_color = color; + } +}; + +Signals.addSignalMethods(AppDisplayItem.prototype); + +function AppDisplay(width, height) { + this._init(width, height); +} + +AppDisplay.prototype = { + _init : function(width, height) { + let me = this; + let global = Shell.Global.get(); + this._search = ''; + this._width = width; + this._height = height; + this._appMonitor = new Shell.AppMonitor(); + this._appsStale = true; + this._appMonitor.connect('changed', function(mon) { + me._appsStale = true; + }); + this._grid = new Tidy.Grid({width: width, height: height}); + this._appSet = {}; // Map + this._displayed = {}; // Map + this._selectedIndex = -1; + this._maxItems = this._height / (APPDISPLAY_HEIGHT + APPDISPLAY_PADDING); + this.actor = this._grid; + }, + + _refreshCache: function() { + let me = this; + + if (!this._appsStale) + return; + for (id in this._displayed) + this._displayed[id].destroy(); + this._appSet = {}; + this._displayed = {}; + this._selectedIndex = -1; + let apps = Gio.app_info_get_all(); + for (let i = 0; i < apps.length; i++) { + let appInfo = apps[i]; + let appId = appInfo.get_id(); + this._appSet[appId] = appInfo; + } + this._appsStale = false; + }, + + _removeItem: function(appId) { + let item = this._displayed[appId]; + let group = item.actor; + group.destroy(); + delete this._displayed[appId]; + }, + + _removeAll: function() { + for (appId in this._displayed) + this._removeItem(appId); + }, + + _setDefaultList: function() { + this._removeAll(); + let added = 0; + for (let i = 0; i < DEFAULT_APPLICATIONS.length && added < this._maxItems; i++) { + let appId = DEFAULT_APPLICATIONS[i]; + let appInfo = this._appSet[appId]; + if (appInfo) { + this._filterAdd(appId); + added += 1; + } + } + }, + + _getNDisplayed: function() { + // Is there a better way to do .size() ? + let c = 0; for (i in this._displayed) { c += 1; }; + return c; + }, + + _filterAdd: function(appId) { + let me = this; + + let appInfo = this._appSet[appId]; + + let appDisplayItem = new AppDisplayItem(appInfo, this._width); + appDisplayItem.connect('activate', function() { + appDisplayItem.launch(); + me.emit('activated'); + }); + let group = appDisplayItem.actor; + this._grid.add_actor(group); + this._displayed[appId] = appDisplayItem; + }, + + _filterRemove: function(appId) { + // In the future, do some sort of fade out or other effect here + let item = this._displayed[appId]; + this._removeItem(item); + }, + + _appInfoMatches: function(appInfo, search) { + if (search == null || search == '') + return true; + let name = appInfo.get_name().toLowerCase(); + if (name.indexOf(search) >= 0) + return true; + let description = appInfo.get_description(); + if (description) { + description = description.toLowerCase(); + if (description.indexOf(search) >= 0) + return true; + } + let exec = appInfo.get_executable().toLowerCase(); + if (exec.indexOf(search) >= 0) + return true; + return false; + }, + + _sortApps: function(appIds) { + let me = this; + return appIds.sort(function (a,b) { + let appA = me._appSet[a]; + let appB = me._appSet[b]; + return appA.get_name().localeCompare(appB.get_name()); + }); + }, + + _doSearchFilter: function() { + this._removeAll(); + let matchedApps = []; + for (appId in this._appSet) { + if (matchedApps.length >= this._maxItems) + break; + if (this._displayed[appId]) + continue; + let app = this._appSet[appId]; + if (this._appInfoMatches(app, this._search)) + matchedApps.push(appId); + } + this._sortApps(matchedApps); + for (let i = 0; i < matchedApps.length; i++) { + this._filterAdd(matchedApps[i]); + } + }, + + _redisplay: function() { + this._refreshCache(); + if (!this._search) + this._setDefaultList(); + else + this._doSearchFilter(); + }, + + setSearch: function(text) { + this._search = text.toLowerCase(); + this._redisplay(); + }, + + _findDisplayedByIndex: function(index) { + let displayedActors = this._grid.get_children(); + let actor = displayedActors[index]; + return this._findDisplayedByActor(actor); + }, + + _findDisplayedByActor: function(actor) { + for (appId in this._displayed) { + let item = this._displayed[appId]; + if (item.actor == actor) { + return item; + } + } + return null; + }, + + searchActivate: function() { + if (this._selectedIndex != -1) { + let selected = this._findDisplayedByIndex(this._selectedIndex); + selected.launch(); + this.emit('activated'); + return; + } + let displayedActors = this._grid.get_children(); + if (displayedActors.length != 1) + return; + let selectedActor = displayedActors[0]; + let selectedMenuItem = this._findDisplayedByActor(selectedActor); + selectedMenuItem.launch(); + this.emit('activated'); + }, + + _selectIndex: function(index) { + if (this._selectedIndex != -1) { + let prev = this._findDisplayedByIndex(this._selectedIndex); + prev.markSelected(false); + } + this._selectedIndex = index; + let item = this._findDisplayedByIndex(index); + item.markSelected(true); + }, + + selectUp: function() { + let prev = this._selectedIndex-1; + if (prev < 0) + return; + this._selectIndex(prev); + }, + + selectDown: function() { + let next = this._selectedIndex+1; + let nDisplayed = this._getNDisplayed(); + if (next >= nDisplayed) + return; + this._selectIndex(next); + }, + + show: function() { + this._redisplay(); + this._grid.show(); + }, + + hide: function() { + this._grid.hide(); + } +}; + +Signals.addSignalMethods(AppDisplay.prototype); diff --git a/js/ui/appdisplay.js b/js/ui/appdisplay.js deleted file mode 100644 index 612f0a07e..000000000 --- a/js/ui/appdisplay.js +++ /dev/null @@ -1,351 +0,0 @@ -/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */ - -const Signals = imports.signals; -const Clutter = imports.gi.Clutter; -const Gio = imports.gi.Gio; -const Pango = imports.gi.Pango; -const Gtk = imports.gi.Gtk; - -const Tidy = imports.gi.Tidy; -const Big = imports.gi.Big; -const Meta = imports.gi.Meta; -const Shell = imports.gi.Shell; - -// TODO - move this into GConf once we're not a plugin anymore -// but have taken over metacity -// This list is taken from GNOME Online popular applications -// http://online.gnome.org/applications -// but with nautilus removed -const DEFAULT_APPLICATIONS = [ - 'mozilla-firefox.desktop', - 'gnome-terminal.desktop', - 'evolution.desktop', - 'evince.desktop', - 'gedit.desktop', - 'mozilla-thunderbird.desktop', - 'totem.desktop', - 'gnome-file-roller.desktop', - 'rhythmbox.desktop', - 'epiphany.desktop', - 'xchat.desktop', - 'openoffice.org-1.9-writer.desktop', - 'emacs.desktop', - 'gnome-system-monitor.desktop', - 'openoffice.org-1.9-calc.desktop', - 'eclipse.desktop', - 'openoffice.org-1.9-impress.desktop', - 'vncviewer.desktop' -]; - -const APPDISPLAY_NAME_COLOR = new Clutter.Color(); -APPDISPLAY_NAME_COLOR.from_pixel(0xffffffff); -const APPDISPLAY_COMMENT_COLOR = new Clutter.Color(); -APPDISPLAY_COMMENT_COLOR.from_pixel(0xffffffbb); -const APPDISPLAY_BACKGROUND_COLOR = new Clutter.Color(); -APPDISPLAY_BACKGROUND_COLOR.from_pixel(0x000000ff); -const APPDISPLAY_SELECTED_BACKGROUND_COLOR = new Clutter.Color(); -APPDISPLAY_SELECTED_BACKGROUND_COLOR.from_pixel(0x00ff0055); - -const APPDISPLAY_HEIGHT = 50; -const APPDISPLAY_PADDING = 4; - -function AppDisplayItem(node, width) { - this._init(node, width); -} - -AppDisplayItem.prototype = { - _init: function(appinfo, width) { - let me = this; - this._appinfo = appinfo; - - let name = appinfo.get_name(); - - let icontheme = Gtk.IconTheme.get_default(); - - this._group = new Clutter.Group({reactive: true, - width: width, - height: APPDISPLAY_HEIGHT}); - this._group.connect('button-press-event', function(group, e) { - me.emit('activate'); - return true; - }); - this._bg = new Big.Box({ background_color: APPDISPLAY_BACKGROUND_COLOR, - corner_radius: 4, - x: 0, y: 0, - width: width, height: APPDISPLAY_HEIGHT }); - this._group.add_actor(this._bg); - - this._icon = new Clutter.Texture({ width: 48, height: 48, x: 0, y: 0 }); - let gicon = appinfo.get_icon(); - let path = null; - if (gicon != null) { - let iconinfo = icontheme.lookup_by_gicon(gicon, 48, Gtk.IconLookupFlags.NO_SVG); - if (iconinfo) - path = iconinfo.get_filename(); - } - - if (path) - this._icon.set_from_file(path); - this._group.add_actor(this._icon); - - let comment = appinfo.get_description(); - let text_width = width - (me._icon.width + 4); - this._name = new Clutter.Label({ color: APPDISPLAY_NAME_COLOR, - font_name: "Sans 14px", - width: text_width, - ellipsize: Pango.EllipsizeMode.END, - text: name, - x: this._icon.width + 4, - y: 0}); - this._group.add_actor(this._name); - this._comment = new Clutter.Label({ color: APPDISPLAY_COMMENT_COLOR, - font_name: "Sans 12px", - width: text_width, - ellipsize: Pango.EllipsizeMode.END, - text: comment, - x: this._name.x, - y: this._name.height + 4}) - this._group.add_actor(this._comment); - this.actor = this._group; - }, - launch: function() { - this._appinfo.launch([], null); - }, - appinfo: function () { - return this._appinfo; - }, - markSelected: function(isSelected) { - let color; - if (isSelected) - color = APPDISPLAY_SELECTED_BACKGROUND_COLOR; - else - color = APPDISPLAY_BACKGROUND_COLOR; - this._bg.background_color = color; - } -}; - -Signals.addSignalMethods(AppDisplayItem.prototype); - -function AppDisplay(width, height) { - this._init(width, height); -} - -AppDisplay.prototype = { - _init : function(width, height) { - let me = this; - let global = Shell.Global.get(); - this._search = ''; - this._width = width; - this._height = height; - this._appmonitor = new Shell.AppMonitor(); - this._appsStale = true; - this._appmonitor.connect('changed', function(mon) { - me._appsStale = true; - }); - this._grid = new Tidy.Grid({width: width, height: height}); - this._appset = {}; // Map - this._displayed = {}; // Map - this._selectedIndex = -1; - this._max_items = this._height / (APPDISPLAY_HEIGHT + APPDISPLAY_PADDING); - this.actor = this._grid; - }, - - _refreshCache: function() { - let me = this; - - if (!this._appsStale) - return; - for (id in this._displayed) - this._displayed[id].destroy(); - this._appset = {}; - this._displayed = {}; - this._selectedIndex = -1; - let apps = Gio.app_info_get_all(); - for (let i = 0; i < apps.length; i++) { - let appinfo = apps[i]; - let appid = appinfo.get_id(); - this._appset[appid] = appinfo; - } - this._appsStale = false; - }, - - _removeItem: function(appid) { - let item = this._displayed[appid]; - let group = item.actor; - group.destroy(); - delete this._displayed[appid]; - }, - - _removeAll: function() { - for (appid in this._displayed) - this._removeItem(appid); - }, - - _setDefaultList: function() { - this._removeAll(); - let added = 0; - for (let i = 0; i < DEFAULT_APPLICATIONS.length && added < this._max_items; i++) { - let appid = DEFAULT_APPLICATIONS[i]; - let appinfo = this._appset[appid]; - if (appinfo) { - this._filterAdd(appid); - added += 1; - } - } - }, - - _getNDisplayed: function() { - // Is there a better way to do .size() ? - let c = 0; for (i in this._displayed) { c += 1; }; - return c; - }, - - _filterAdd: function(appid) { - let me = this; - - let appinfo = this._appset[appid]; - let name = appinfo.get_name(); - let index = this._getNDisplayed(); - - let appdisplay = new AppDisplayItem(appinfo, this._width); - appdisplay.connect('activate', function() { - appdisplay.launch(); - me.emit('activated'); - }); - let group = appdisplay.actor; - this._grid.add_actor(group); - this._displayed[appid] = appdisplay; - }, - - _filterRemove: function(appid) { - // In the future, do some sort of fade out or other effect here - let item = this._displayed[appid]; - this._removeItem(item); - }, - - _appinfoMatches: function(appinfo, search) { - if (search == null || search == '') - return true; - let name = appinfo.get_name().toLowerCase(); - if (name.indexOf(search) >= 0) - return true; - let description = appinfo.get_description(); - if (description) { - description = description.toLowerCase(); - if (description.indexOf(search) >= 0) - return true; - } - let exec = appinfo.get_executable().toLowerCase(); - if (exec.indexOf(search) >= 0) - return true; - return false; - }, - - _sortApps: function(appids) { - let me = this; - return appids.sort(function (a,b) { - let appA = me._appset[a]; - let appB = me._appset[b]; - return appA.get_name().localeCompare(appB.get_name()); - }); - }, - - _doSearchFilter: function() { - this._removeAll(); - let matchedApps = []; - for (appid in this._appset) { - if (matchedApps.length >= this._max_items) - break; - if (this._displayed[appid]) - continue; - let app = this._appset[appid]; - if (this._appinfoMatches(app, this._search)) - matchedApps.push(appid); - } - this._sortApps(matchedApps); - for (let i = 0; i < matchedApps.length; i++) { - this._filterAdd(matchedApps[i]); - } - }, - - _redisplay: function() { - this._refreshCache(); - if (!this._search) - this._setDefaultList(); - else - this._doSearchFilter(); - }, - - setSearch: function(text) { - this._search = text.toLowerCase(); - this._redisplay(); - }, - - _findDisplayedByIndex: function(index) { - let displayedActors = this._grid.get_children(); - let actor = displayedActors[index]; - return this._findDisplayedByActor(actor); - }, - - _findDisplayedByActor: function(actor) { - for (appid in this._displayed) { - let item = this._displayed[appid]; - if (item.actor == actor) { - return item; - } - } - return null; - }, - - searchActivate: function() { - if (this._selectedIndex != -1) { - let selected = this._findDisplayedByIndex(this._selectedIndex); - selected.launch(); - this.emit('activated'); - return; - } - let displayedActors = this._grid.get_children(); - if (displayedActors.length != 1) - return; - let selectedActor = displayedActors[0]; - let selectedMenuItem = this._findDisplayedByActor(selectedActor); - selectedMenuItem.launch(); - this.emit('activated'); - }, - - _selectIndex: function(index) { - if (this._selectedIndex != -1) { - let prev = this._findDisplayedByIndex(this._selectedIndex); - prev.markSelected(false); - } - this._selectedIndex = index; - let item = this._findDisplayedByIndex(index); - item.markSelected(true); - }, - - selectUp: function() { - let prev = this._selectedIndex-1; - if (prev < 0) - return; - this._selectIndex(prev); - }, - - selectDown: function() { - let next = this._selectedIndex+1; - let nDisplayed = this._getNDisplayed(); - if (next >= nDisplayed) - return; - this._selectIndex(next); - }, - - show: function() { - this._redisplay(); - this._grid.show(); - }, - - hide: function() { - this._grid.hide(); - } -}; - -Signals.addSignalMethods(AppDisplay.prototype); diff --git a/js/ui/main.js b/js/ui/main.js index 62fa65c41..fb07085fb 100644 --- a/js/ui/main.js +++ b/js/ui/main.js @@ -8,8 +8,8 @@ const Tweener = imports.tweener.tweener; const Panel = imports.ui.panel; const Overlay = imports.ui.overlay; -const RunDialog = imports.ui.run_dialog; -const WindowManager = imports.ui.windowmanager; +const RunDialog = imports.ui.runDialog; +const WindowManager = imports.ui.windowManager; const DEFAULT_BACKGROUND_COLOR = new Clutter.Color(); DEFAULT_BACKGROUND_COLOR.from_pixel(0x2266bbff); @@ -17,7 +17,7 @@ DEFAULT_BACKGROUND_COLOR.from_pixel(0x2266bbff); let panel = null; let overlay = null; let overlayActive = false; -let run_dialog = null; +let runDialog = null; let wm = null; // The "FrameTicker" object is an object used to feed new frames to Tweener @@ -103,15 +103,15 @@ function start() { global.connect('panel-run-dialog', function(panel) { // Make sure not more than one run dialog is shown. - if (!run_dialog) { - run_dialog = new RunDialog.RunDialog(); + if (!runDialog) { + runDialog = new RunDialog.RunDialog(); let end_handler = function() { - run_dialog.destroy(); - run_dialog = null; + runDialog.destroy(); + runDialog = null; }; - run_dialog.connect('run', end_handler); - run_dialog.connect('cancel', end_handler); - if (!run_dialog.show()) + runDialog.connect('run', end_handler); + runDialog.connect('cancel', end_handler); + if (!runDialog.show()) end_handler(); } }); diff --git a/js/ui/overlay.js b/js/ui/overlay.js index fc0b36ba3..68095bd40 100644 --- a/js/ui/overlay.js +++ b/js/ui/overlay.js @@ -13,7 +13,7 @@ const Panel = imports.ui.panel; const Meta = imports.gi.Meta; const Shell = imports.gi.Shell; const Big = imports.gi.Big; -const AppDisplay = imports.ui.appdisplay; +const AppDisplay = imports.ui.appDisplay; const OVERLAY_BACKGROUND_COLOR = new Clutter.Color(); OVERLAY_BACKGROUND_COLOR.from_pixel(0x000000ff); @@ -75,13 +75,13 @@ Sideshow.prototype = { let text = me._searchEntry.text; me._searchQueued = false; me._searchActive = text != ''; - me._appdisplay.setSearch(text); + me._appDisplay.setSearch(text); return false; }); }); this._searchEntry.connect('activate', function (se) { me._searchEntry.text = ''; - me._appdisplay.searchActivate(); + me._appDisplay.searchActivate(); return true; }); this._searchEntry.connect('key-press-event', function (se, e) { @@ -90,10 +90,10 @@ Sideshow.prototype = { me._searchEntry.text = ''; return true; } else if (code == 111) { - me._appdisplay.selectUp(); + me._appDisplay.selectUp(); return true; } else if (code == 116) { - me._appdisplay.selectDown(); + me._appDisplay.selectDown(); return true; } return false; @@ -108,19 +108,19 @@ Sideshow.prototype = { this.actor.add_actor(appsText); let menuY = appsText.y + appsText.height + 6; - this._appdisplay = new AppDisplay.AppDisplay(width, global.screen_height - menuY); - this._appdisplay.actor.x = SIDESHOW_PAD; - this._appdisplay.actor.y = menuY; - this.actor.add_actor(this._appdisplay.actor); + this._appDisplay = new AppDisplay.AppDisplay(width, global.screen_height - menuY); + this._appDisplay.actor.x = SIDESHOW_PAD; + this._appDisplay.actor.y = menuY; + this.actor.add_actor(this._appDisplay.actor); /* Proxy the activated signal */ - this._appdisplay.connect('activated', function(appdisplay) { + this._appDisplay.connect('activated', function(appDisplay) { me.emit('activated'); }); }, show: function() { - this._appdisplay.show(); + this._appDisplay.show(); }, hide: function() { diff --git a/js/ui/runDialog.js b/js/ui/runDialog.js new file mode 100644 index 000000000..fdfd36a8c --- /dev/null +++ b/js/ui/runDialog.js @@ -0,0 +1,133 @@ +/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */ + +const Signals = imports.signals; +const Shell = imports.gi.Shell; +const Clutter = imports.gi.Clutter; + +const Main = imports.ui.main; + +const OVERLAY_COLOR = new Clutter.Color(); +OVERLAY_COLOR.from_pixel(0x00000044); + +const BOX_BACKGROUND_COLOR = new Clutter.Color(); +BOX_BACKGROUND_COLOR.from_pixel(0x000000cc); + +const BOX_TEXT_COLOR = new Clutter.Color(); +BOX_TEXT_COLOR.from_pixel(0xffffffff); + +const BOX_WIDTH = 320; +const BOX_HEIGHT = 56; + +function RunDialog() { + this._init(); +}; + +RunDialog.prototype = { + _init : function() { + let global = Shell.Global.get(); + + // All actors are inside _group. We create it initially + // hidden then show it in show() + this._group = new Clutter.Group({ visible: false }); + global.stage.add_actor(this._group); + + this._overlay = new Clutter.Rectangle({ color: OVERLAY_COLOR, + width: global.screen_width, + height: global.screen_height, + border_width: 0, + reactive: true }); + this._group.add_actor(this._overlay); + + let boxGroup = new Clutter.Group(); + boxGroup.set_position((global.screen_width - BOX_WIDTH) / 2, + (global.screen_height - BOX_HEIGHT) / 2); + this._group.add_actor(boxGroup); + + let box = new Clutter.Rectangle({ color: BOX_BACKGROUND_COLOR, + reactive: false, + width: BOX_WIDTH, + height: BOX_HEIGHT, + border_width: 0 }); + boxGroup.add_actor(box); + + let label = new Clutter.Label({ color: BOX_TEXT_COLOR, + font_name: '18px Sans', + text: 'Please enter a command:' }); + label.set_position(6, 6); + boxGroup.add_actor(label); + + this._entry = new Clutter.Entry({ color: BOX_TEXT_COLOR, + font_name: '20px Sans Bold', + reactive: true, + text: '', + entry_padding: 0, + width: BOX_WIDTH - 12, + height: BOX_HEIGHT - 12 }); + // TODO: Implement relative positioning using Tidy. + this._entry.set_position(6, 30); + boxGroup.add_actor(this._entry); + + let me = this; + + this._entry.connect('activate', function (o, e) { + me.hide(); + me._run(o.get_text()); + return false; + }); + + }, + + _run : function(command) { + if (command) { + var p = new Shell.Process({'args' : [command]}); + try { + p.run(); + } catch (e) { + // TODO: Give the user direct feedback. + log('Could not run command ' + command + '.'); + } + } + + this.emit('run'); + }, + + show : function() { + let me = this; + + if (this._group.visible) // Already shown + return false; + + if (!Main.startModal()) + return false; + + this._group.show_all(); + + this._entry.connect('key-press-event', function(o, e) { + if (e.get_code() == 9) { + me.hide(); + me.emit('cancel'); + return true; + } else + return false; + }); + + let global = Shell.Global.get(); + global.stage.set_key_focus(this._entry); + + return true; + }, + + hide : function() { + if (!this._group.visible) + return; + + this._group.hide(); + Main.endModal(); + }, + + destroy : function(){ + this.hide(); + this._group.destroy(); + } +}; +Signals.addSignalMethods(RunDialog.prototype); diff --git a/js/ui/run_dialog.js b/js/ui/run_dialog.js deleted file mode 100644 index fdfd36a8c..000000000 --- a/js/ui/run_dialog.js +++ /dev/null @@ -1,133 +0,0 @@ -/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */ - -const Signals = imports.signals; -const Shell = imports.gi.Shell; -const Clutter = imports.gi.Clutter; - -const Main = imports.ui.main; - -const OVERLAY_COLOR = new Clutter.Color(); -OVERLAY_COLOR.from_pixel(0x00000044); - -const BOX_BACKGROUND_COLOR = new Clutter.Color(); -BOX_BACKGROUND_COLOR.from_pixel(0x000000cc); - -const BOX_TEXT_COLOR = new Clutter.Color(); -BOX_TEXT_COLOR.from_pixel(0xffffffff); - -const BOX_WIDTH = 320; -const BOX_HEIGHT = 56; - -function RunDialog() { - this._init(); -}; - -RunDialog.prototype = { - _init : function() { - let global = Shell.Global.get(); - - // All actors are inside _group. We create it initially - // hidden then show it in show() - this._group = new Clutter.Group({ visible: false }); - global.stage.add_actor(this._group); - - this._overlay = new Clutter.Rectangle({ color: OVERLAY_COLOR, - width: global.screen_width, - height: global.screen_height, - border_width: 0, - reactive: true }); - this._group.add_actor(this._overlay); - - let boxGroup = new Clutter.Group(); - boxGroup.set_position((global.screen_width - BOX_WIDTH) / 2, - (global.screen_height - BOX_HEIGHT) / 2); - this._group.add_actor(boxGroup); - - let box = new Clutter.Rectangle({ color: BOX_BACKGROUND_COLOR, - reactive: false, - width: BOX_WIDTH, - height: BOX_HEIGHT, - border_width: 0 }); - boxGroup.add_actor(box); - - let label = new Clutter.Label({ color: BOX_TEXT_COLOR, - font_name: '18px Sans', - text: 'Please enter a command:' }); - label.set_position(6, 6); - boxGroup.add_actor(label); - - this._entry = new Clutter.Entry({ color: BOX_TEXT_COLOR, - font_name: '20px Sans Bold', - reactive: true, - text: '', - entry_padding: 0, - width: BOX_WIDTH - 12, - height: BOX_HEIGHT - 12 }); - // TODO: Implement relative positioning using Tidy. - this._entry.set_position(6, 30); - boxGroup.add_actor(this._entry); - - let me = this; - - this._entry.connect('activate', function (o, e) { - me.hide(); - me._run(o.get_text()); - return false; - }); - - }, - - _run : function(command) { - if (command) { - var p = new Shell.Process({'args' : [command]}); - try { - p.run(); - } catch (e) { - // TODO: Give the user direct feedback. - log('Could not run command ' + command + '.'); - } - } - - this.emit('run'); - }, - - show : function() { - let me = this; - - if (this._group.visible) // Already shown - return false; - - if (!Main.startModal()) - return false; - - this._group.show_all(); - - this._entry.connect('key-press-event', function(o, e) { - if (e.get_code() == 9) { - me.hide(); - me.emit('cancel'); - return true; - } else - return false; - }); - - let global = Shell.Global.get(); - global.stage.set_key_focus(this._entry); - - return true; - }, - - hide : function() { - if (!this._group.visible) - return; - - this._group.hide(); - Main.endModal(); - }, - - destroy : function(){ - this.hide(); - this._group.destroy(); - } -}; -Signals.addSignalMethods(RunDialog.prototype); diff --git a/js/ui/windowManager.js b/js/ui/windowManager.js new file mode 100644 index 000000000..4694ea380 --- /dev/null +++ b/js/ui/windowManager.js @@ -0,0 +1,131 @@ +/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */ + +const Clutter = imports.gi.Clutter; +const Mainloop = imports.mainloop; +const Meta = imports.gi.Meta; +const Shell = imports.gi.Shell; +const Tweener = imports.tweener.tweener; + +const Main = imports.ui.main; + +const SWITCH_ANIMATION_TIME = 0.5; + +function WindowManager() { + this._init(); +} + +WindowManager.prototype = { + _init : function() { + let me = this; + + this._global = Shell.Global.get(); + this._shellwm = this._global.window_manager; + + this._switchData = null; + this._shellwm.connect('switch-workspace', + function(o, from, to, direction) { + let actors = me._shellwm.get_switch_workspace_actors(); + me.switchWorkspace(actors, from, to, direction); + }); + this._shellwm.connect('kill-switch-workspace', + function(o) { + me.switchWorkspaceDone(); + }); + }, + + switchWorkspace : function(windows, from, to, direction) { + // If the overlay is active, it will do the transition itself + if (Main.overlayActive) { + this._shellwm.completed_switch_workspace(); + return; + } + + /* @direction is the direction that the "camera" moves, so the + * screen contents have to move one screen's worth in the + * opposite direction. + */ + let xDest = 0, yDest = 0; + + if (direction == Meta.MotionDirection.UP || + direction == Meta.MotionDirection.UP_LEFT || + direction == Meta.MotionDirection.UP_RIGHT) + yDest = this._global.screen_height; + else if (direction == Meta.MotionDirection.DOWN || + direction == Meta.MotionDirection.DOWN_LEFT || + direction == Meta.MotionDirection.DOWN_RIGHT) + yDest = -this._global.screen_height; + + if (direction == Meta.MotionDirection.LEFT || + direction == Meta.MotionDirection.UP_LEFT || + direction == Meta.MotionDirection.DOWN_LEFT) + xDest = this._global.screen_width; + else if (direction == Meta.MotionDirection.RIGHT || + direction == Meta.MotionDirection.UP_RIGHT || + direction == Meta.MotionDirection.DOWN_RIGHT) + xDest = -this._global.screen_width; + + let switchData = {}; + this._switchData = switchData; + switchData.inGroup = new Clutter.Group(); + switchData.outGroup = new Clutter.Group(); + switchData.windows = []; + + let wgroup = this._global.window_group; + wgroup.add_actor(switchData.inGroup); + wgroup.add_actor(switchData.outGroup); + + for (let i = 0; i < windows.length; i++) { + let window = windows[i]; + if (window.get_workspace() == from) { + switchData.windows.push({ window: window, + parent: window.get_parent() }); + window.reparent(switchData.outGroup); + } else if (window.get_workspace() == to) { + switchData.windows.push({ window: window, + parent: window.get_parent() }); + window.reparent(switchData.inGroup); + window.show_all(); + } + } + + switchData.inGroup.set_position(-xDest, -yDest); + switchData.inGroup.raise_top(); + + Tweener.addTween(switchData.outGroup, + { x: xDest, + y: yDest, + time: SWITCH_ANIMATION_TIME, + transition: "easeOutBack", + onComplete: this.switchWorkspaceDone + }); + Tweener.addTween(switchData.inGroup, + { x: 0, + y: 0, + time: SWITCH_ANIMATION_TIME, + transition: "easeOutBack" + }); + }, + + switchWorkspaceDone : function() { + let switchData = this._switchData; + if (!switchData) + return; + this._switchData = null; + + for (let i = 0; i < switchData.windows.length; i++) { + let w = switchData.windows[i]; + if (w.window.get_parent() == switchData.outGroup) { + w.window.reparent(w.parent); + w.window.hide(); + } else + w.window.reparent(w.parent); + } + Tweener.removeTweens(switchData.inGroup); + Tweener.removeTweens(switchData.outGroup); + switchData.inGroup.destroy(); + switchData.outGroup.destroy(); + + this._shellwm.completed_switch_workspace(); + } + +}; diff --git a/js/ui/windowmanager.js b/js/ui/windowmanager.js deleted file mode 100644 index 4694ea380..000000000 --- a/js/ui/windowmanager.js +++ /dev/null @@ -1,131 +0,0 @@ -/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */ - -const Clutter = imports.gi.Clutter; -const Mainloop = imports.mainloop; -const Meta = imports.gi.Meta; -const Shell = imports.gi.Shell; -const Tweener = imports.tweener.tweener; - -const Main = imports.ui.main; - -const SWITCH_ANIMATION_TIME = 0.5; - -function WindowManager() { - this._init(); -} - -WindowManager.prototype = { - _init : function() { - let me = this; - - this._global = Shell.Global.get(); - this._shellwm = this._global.window_manager; - - this._switchData = null; - this._shellwm.connect('switch-workspace', - function(o, from, to, direction) { - let actors = me._shellwm.get_switch_workspace_actors(); - me.switchWorkspace(actors, from, to, direction); - }); - this._shellwm.connect('kill-switch-workspace', - function(o) { - me.switchWorkspaceDone(); - }); - }, - - switchWorkspace : function(windows, from, to, direction) { - // If the overlay is active, it will do the transition itself - if (Main.overlayActive) { - this._shellwm.completed_switch_workspace(); - return; - } - - /* @direction is the direction that the "camera" moves, so the - * screen contents have to move one screen's worth in the - * opposite direction. - */ - let xDest = 0, yDest = 0; - - if (direction == Meta.MotionDirection.UP || - direction == Meta.MotionDirection.UP_LEFT || - direction == Meta.MotionDirection.UP_RIGHT) - yDest = this._global.screen_height; - else if (direction == Meta.MotionDirection.DOWN || - direction == Meta.MotionDirection.DOWN_LEFT || - direction == Meta.MotionDirection.DOWN_RIGHT) - yDest = -this._global.screen_height; - - if (direction == Meta.MotionDirection.LEFT || - direction == Meta.MotionDirection.UP_LEFT || - direction == Meta.MotionDirection.DOWN_LEFT) - xDest = this._global.screen_width; - else if (direction == Meta.MotionDirection.RIGHT || - direction == Meta.MotionDirection.UP_RIGHT || - direction == Meta.MotionDirection.DOWN_RIGHT) - xDest = -this._global.screen_width; - - let switchData = {}; - this._switchData = switchData; - switchData.inGroup = new Clutter.Group(); - switchData.outGroup = new Clutter.Group(); - switchData.windows = []; - - let wgroup = this._global.window_group; - wgroup.add_actor(switchData.inGroup); - wgroup.add_actor(switchData.outGroup); - - for (let i = 0; i < windows.length; i++) { - let window = windows[i]; - if (window.get_workspace() == from) { - switchData.windows.push({ window: window, - parent: window.get_parent() }); - window.reparent(switchData.outGroup); - } else if (window.get_workspace() == to) { - switchData.windows.push({ window: window, - parent: window.get_parent() }); - window.reparent(switchData.inGroup); - window.show_all(); - } - } - - switchData.inGroup.set_position(-xDest, -yDest); - switchData.inGroup.raise_top(); - - Tweener.addTween(switchData.outGroup, - { x: xDest, - y: yDest, - time: SWITCH_ANIMATION_TIME, - transition: "easeOutBack", - onComplete: this.switchWorkspaceDone - }); - Tweener.addTween(switchData.inGroup, - { x: 0, - y: 0, - time: SWITCH_ANIMATION_TIME, - transition: "easeOutBack" - }); - }, - - switchWorkspaceDone : function() { - let switchData = this._switchData; - if (!switchData) - return; - this._switchData = null; - - for (let i = 0; i < switchData.windows.length; i++) { - let w = switchData.windows[i]; - if (w.window.get_parent() == switchData.outGroup) { - w.window.reparent(w.parent); - w.window.hide(); - } else - w.window.reparent(w.parent); - } - Tweener.removeTweens(switchData.inGroup); - Tweener.removeTweens(switchData.outGroup); - switchData.inGroup.destroy(); - switchData.outGroup.destroy(); - - this._shellwm.completed_switch_workspace(); - } - -};